//
//  WillNRViewController.m
//  MaxMovie
//
//  Created by Maxdong on 14-12-24.
//  Copyright (c) 2014年 lanou3g.com 蓝欧科技. All rights reserved.
//

#import "WillNRViewController.h"
#import "WillShow.h"
#import "WillNRModel.h"
#import "NetworkHandler.h"
#import "UIImageView+WebCache.h"

//剧照
#import "ImageViewController.h"
//电影播放
#import "VideoPlayerViewController.h"


@interface WillNRViewController ()
@property (nonatomic, retain)NSMutableDictionary *dataDic;
@end

@implementation WillNRViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"✨Comming Soon✨";
    }
    return self;
    
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIButton * leftb =[UIButton buttonWithType:UIButtonTypeSystem];
    leftb.frame =CGRectMake(20, 20, 20, 20);
    UIImage * img1 =[UIImage imageNamed:@"left.png"];
    [leftb setBackgroundImage:img1 forState:UIControlStateNormal];
    [leftb addTarget:self action:@selector(leftbAction:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithCustomView:leftb];
    
    //滚动视图
    UIScrollView *BigScrollView = [[UIScrollView alloc]initWithFrame:self.view.bounds];
    
    BigScrollView.showsVerticalScrollIndicator = FALSE;
    BigScrollView.showsHorizontalScrollIndicator = FALSE;
    [self.view addSubview:BigScrollView];
    [BigScrollView release];
  
    
    //网络请求
    [NetworkHandler connectioonNetGETDataWithURLString:self.myUrl completion:^(id result) {
        self.getData = result;
        
        //背景大图
        UIImageView *tmpBig = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 140)];
        tmpBig.image = [UIImage imageNamed:@"backxiao.png"];
        [tmpBig setUserInteractionEnabled:YES];//使他响应
        [BigScrollView addSubview:tmpBig];
        [tmpBig release];
        self.BigImageView = tmpBig;
        
        
        //电影小图
        UIImageView *tmpSmall = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 90, 120)];
        [tmpBig addSubview:tmpSmall];
        [tmpSmall release];
        self.SmallImage = tmpSmall;
        
        [tmpSmall setImageWithURL:[NSURL URLWithString:[self.getData objectForKey:@"img"]]];
        
        
        
        //片名
        UILabel *tmpType = [[UILabel alloc]initWithFrame:CGRectMake(115, 15, 250, 30)];
        [tmpType setTextColor:[UIColor yellowColor]];
        tmpType.font = [UIFont boldSystemFontOfSize:15];
        [tmpBig addSubview:tmpType];
        [tmpType release];
        self.typeLabel = tmpType;
        
        [tmpType setText:[NSString stringWithFormat:@"★ %@ ★",[self.getData objectForKey:@"t"]]];
        
        //日期
        UILabel *tmpDate = [[UILabel alloc]initWithFrame:CGRectMake(115, 60, 200, 30)];
        [tmpDate setTextColor:[UIColor yellowColor]];
        tmpDate.font = [UIFont boldSystemFontOfSize:15];
        [tmpBig addSubview:tmpDate];
        [tmpDate release];
        self.typeLabel = tmpDate;
        
        [tmpDate setText:[NSString stringWithFormat:@"★ %@上映 ★",[self.getData objectForKey:@"rd"]]];
        
        
        //预告按钮
        self.yugaoButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.yugaoButton.frame = CGRectMake(100, 100, 160, 30);
        self.yugaoButton.font = [UIFont systemFontOfSize:15];
        [self.yugaoButton setShowsTouchWhenHighlighted:YES];
        [self.yugaoButton setTitle:@" ▶ 点击播放预告片" forState:UIControlStateNormal];
        [self.yugaoButton setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal];
        [self.yugaoButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
        [tmpBig addSubview:self.yugaoButton];
        [self.yugaoButton release];
        
        
        //导演
        UILabel *tmpBigLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 150, 300, 80)];
        
        tmpBigLabel.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"yanzhi.png"]];
        [BigScrollView addSubview:tmpBigLabel];
        [tmpBigLabel release];
        self.DYBigLabel = tmpBigLabel;
        
        
        UILabel *DYLabel = [[UILabel alloc]initWithFrame:CGRectMake(50, 10, 200, 25)];
        DYLabel.font = [UIFont boldSystemFontOfSize:14];
        [DYLabel setTextColor:[UIColor blackColor]];
        [tmpBigLabel addSubview:DYLabel];
        [DYLabel release];
        
        UILabel *YYLabel = [[UILabel alloc]initWithFrame:CGRectMake(50, 45, 200, 25)];
        YYLabel.font = [UIFont boldSystemFontOfSize:14];
        [YYLabel setTextColor:[UIColor blackColor]];
        [tmpBigLabel addSubview:YYLabel];
        [YYLabel release];
        [DYLabel setText:[NSString stringWithFormat:@"导演：%@",[self.getData objectForKey:@"dN"]]];
        [YYLabel setText:[NSString stringWithFormat:@"演员：%@ , %@",[self.getData objectForKey:@"aN1"],[self.getData objectForKey:@"aN2"]]];
        
        
        //剧照图片
//        UIScrollView * scroll= [[UIScrollView alloc] initWithFrame:CGRectMake(5, 240, 300, 80)];
//        scroll.contentSize =CGSizeMake(self.view.frame.size.width, 100);
//        scroll.pagingEnabled =YES;
//        [BigScrollView addSubview:scroll];
        
        UILabel *tmpImage = [[UILabel alloc]initWithFrame:CGRectMake(5, 240, 300, 80)];
        
        tmpImage.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"juzhao.png"]];
        [BigScrollView addSubview:tmpImage];
        self.ImageLabel = tmpImage;
        [tmpImage release];

        
        
        
        
        //剧照
        NSArray * arr =[self.getData objectForKey:@"movieimg"];
        NSLog(@"arr =%@",arr);
        
        for (int i =0; i<4; i++) {
            self.Button1 = [UIButton buttonWithType:UIButtonTypeSystem];
            _Button1.frame=CGRectMake((i*105)-(i-1)*40, 15, 50, 50);
            
            NSDictionary * dic =[arr objectAtIndex:i];
            NSURL * url =[NSURL URLWithString:[dic objectForKey:@"image"]];
            NSData * data =[NSData dataWithContentsOfURL:url];
            UIImage * img =[UIImage imageWithData:data];
            [_Button1 setBackgroundImage:img forState:UIControlStateNormal];
            [tmpImage addSubview:_Button1];
            //剧照点击事件
            [_Button1 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
            
        }[_Button1 release];
        
        UILabel *jqLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 340, 300, 30)];
        jqLabel.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"juqing"]];
        [BigScrollView addSubview:jqLabel];
        [jqLabel release];
        self.juqingLabel = jqLabel;
        
        
        //剧情
        UILabel *tmpJQ = [[UILabel alloc]initWithFrame:CGRectMake(26, 370, 275, self.view.bounds.size.height)];
        //    tmpJQ.backgroundColor = [UIColor purpleColor];
        tmpJQ.font = [UIFont boldSystemFontOfSize: 14];
        [tmpJQ setTextColor:[UIColor blackColor]];
        [BigScrollView addSubview:tmpJQ];
        
        [tmpJQ release];
        self.JQLabel = tmpJQ;
        
        //剧情简介
        [tmpJQ setText:[self.getData objectForKey:@"pt"]];
        //自适应
        [tmpJQ setNumberOfLines:0];
        [tmpJQ sizeToFit];
        
        
        BigScrollView.contentSize = CGSizeMake(0, tmpJQ.bounds.size.height + 380);
        
    }];
    
}

//剧照点击事件
- (void)buttonAction:(id)sender
{
    
    ImageViewController * imageVC=[[ImageViewController alloc] init];
    imageVC.title =@"✨剧照列表✨";
    UINavigationController * imNavi=[[UINavigationController alloc] initWithRootViewController:imageVC];
    
    [imNavi.navigationBar setBarTintColor:[UIColor colorWithRed:128.0 / 255.0 green:0.0 / 255.0 blue:128.0 / 255.0 alpha:1.0]];
    [imNavi.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:255.0 / 255.0 green:215.0 / 255.0 blue:0.0 / 255.0 alpha:1.0], NSForegroundColorAttributeName, nil]];
   // [self.navigationController pushViewController:imNavi animated:YES];
    [self presentViewController:imNavi animated:YES
                     completion:^{
                         
                     }];
    //[imNavi release];
}

-(void)buttonClicked:(UIButton *)button
{
    VideoPlayerViewController *moviePlayer = [[[VideoPlayerViewController alloc] init] autorelease];
    //将视频地址传过去
    [NetworkHandler connectioonNetGETDataWithURLString:self.myUrl completion:^(id result) {
        self.getData = result;
        
        moviePlayer.movieURL = [NSURL URLWithString:[self.getData objectForKey:@"m"]];
        
        //然后播放就OK了
        [moviePlayer readyPlayer];
        [self presentModalViewController:moviePlayer animated:NO];
    }];
    
    NSLog(@"点击按钮");
}

- (void)leftbAction:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
